//波次单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var user_name=thisform.find('input[name=user_name]').val();
		var user_phone=thisform.find('input[name=user_phone]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var is_delivery=thisform.find('input[name=is_delivery]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var time_cate=thisform.find('input[name=time_cate]').val();
		var has_push=thisform.find('input[name=has_push]').val();
		$('#pushorderlistDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#pushorderlistDatagrid').datagrid({
			queryParams:{
				user_phone:user_phone,
				order_no:order_no,
				user_name:user_name,
				mailNo:mailNo,
				time_cate:time_cate,
				has_push:has_push,
				start_time:start_time,
				end_time:end_time,
				is_delivery:1
			}
		});
	})
	$('#pushorderlist_mailNo').textbox('textbox').keydown(function (e) {
	    if (e.keyCode == 13) {
	       $('.sumitBar').click();
	    }
	});
	//出库
	var torder_no='';
	$('.sumitBar').click(function(){
		// console.log(123);
		var thisform=$(this).parent('form');
		var mailNo=thisform.find('input[name=mailNo]').val();

		thisform.find('input[name=mailNo]').parent().find('input').eq(0).focus();
		$("#pushorderlist_mailNo").textbox("setValue", "");
		if(mailNo==""){
			layer.msg("没有运单号！");
			return false;
		}else{
			$.ajax({
				type:"POST",
				url:outboundOrderUrl2,
				data:{mailNo:mailNo},
				success: function(result){
					if(result.status){
						play_audio_file('success');
						torder_no=torder_no+result.order_no+'/';
						layer.msg(torder_no,function(){
							$('#pushorderlistDatagrid').datagrid('reload');
						});
					}else{
						// $.messager.alert('错误提示',result.message,'error');
						play_audio_file('failed');
						layer.msg(result.message);
					}
					
				}
			});
		}
	})
	$('#pushorderlistDatagrid').datagrid({
		url:getpushOrderlistUrl,
		title:'订单列表',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'ids',title:'',
			formatter:function(value,row,index){
				return '<a target="_blank" href="'+outboundPrinterUrl+'&order=Pushorder&orderdetail=Pushordergoods&id='+value+'&outbound=1">出库单</a>';
			}
		},
		{field:'order_no',title:'订单编码',sortable:true},
		{field:'user_name',title:'客户姓名'},
		{field:'user_phone',title:'联系电话'},
		{field:'user_idcard',title:'身份证'},
		{field:'user_address',title:'客户详细地址'},
		{field:'logistics_no',title:'物流单号'},
		{field:'logiscompany_name',title:'物流企业名称'},
		{field:'is_delivery',title:'已出库',sortable:true,
			formatter:function(value,row,index){
				if (value==0){
					return "否";
				} else {
					return "是";
				}
			}
		},
		{field:'push_outboundstatus',title:'已申报',sortable:true,
			formatter:function(value,row,index){
				if (value==0){
					return "否";
				} else {
					return "是";
				}
			}
		},
		{field:'delivery_time',title:'出库时间'},
		{field:'push_outboundtime',title:'申报时间'}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		onLoadSuccess:function(){
			//回车
			// $('#pushorderlist_mailNo').textbox('textbox').keydown(function (e) {
		//         if (e.keyCode == 13) {
		//            $('.sumitBar').click();
		//         }
		//     });
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
pushorderlistObj={
	outboundBar:function(){	//出库
		var pushorderlistRow=$('#pushorderlistDatagrid').datagrid('getSelections');
        if(pushorderlistRow.length<1){
			$.messager.alert('错误提示','请选择列表数据','error');
		}else{
			$.messager.confirm('提示','确认出库吗！',function(r){
				if(r){
					var ids=[];
					for(var i=0;i<pushorderlistRow.length;i++){
						ids.push(pushorderlistRow[i].id);
					}
					var id=ids.join(',');
					$.post(outboundOrderUrl,{id:id},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
							$('#pushorderlistDatagrid').datagrid('reload');
						}else{
							$.messager.alert('提示',result.message,'info');
							$('#pushorderlistDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
				}
			});
        }
	},
	excelBar:function(){	//导出excel
		var thisform=$('#pushorderlistSearchForm');
		// console.log(thisform);
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var user_name=thisform.find('input[name=user_name]').val();
		var user_phone=thisform.find('input[name=user_phone]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var time_cate=thisform.find('input[name=time_cate]').val();
		// console.log(order_no);
		url=getpushOrderlistUrl+"&excel=1&rows=6000";
		if(order_no!=''){
			url=url+"&order_no="+order_no;
		}
		if(mailNo!=''){
			url=url+"&mailNo="+mailNo;
		}
		if(user_phone!=''){
			url=url+"&user_phone="+user_phone;
		}
		if(user_name!=''){
			url=url+"&user_name="+user_name;
		}
		
		if(time_cate!=0){
			url=url+"&time_cate="+time_cate;
			if(start_time!=0){
				url=url+"&start_time="+start_time;
			}
			if(end_time!=0){
				url=url+"&end_time="+end_time;
			}
		}
		window.location.href=url;
	},
	pushoutboundBar:function(){
		var Row=$('#pushorderlistDatagrid').datagrid('getSelections');
		var text='确定申报吗！';
        if (Row.length>0){
        	$.messager.confirm('提示',text,function(r){
                if (r){
					var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(pushoutboundstorageUrl,{plan_receipts_id:Row[0].order_no,id:id,receive_no:Row[0].receive_no},function(result){
						if (result.status){
							$.messager.alert('推送成功',result.message);
						}else{
							$.messager.alert('错误提示',result.message,'error');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('提示','请选择列表数据','error');
		}
	},
	removeBar:function(){//删除数据
		var Row=$('#pushorderlistDatagrid').datagrid('getSelections');
        if (Row.length>0){
        	$.messager.confirm('删除提示','真的要删除这'+Row.length+'个信息吗?',function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
                    $.post(DelUrl,{id:id},function(result){
                        if (result.status){
							$.messager.alert('提示信息',result.message,'info',function(r){     
								$('#pushorderlistDatagrid').datagrid('reload'); 
							});
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	showAdvanceBar:function(){
		$('#pushorderlistDatagrid').datagrid({ queryParams:{show_advance:1}});
	},
	showAll:function(){
		$('#pushorderlistDatagrid').datagrid({ queryParams:''});
	}
}